var pageIndex = 0;     //页面索引初始值  
var pageSize = 10;     //每页显示条数初始化，修改显示条数，修改这里即可  
var total = 0;
$(function()
{
	total = $("#chushitotal").val();
	initPage();
	//全局捕获回车键
	document.onkeydown = keydown;
	function keydown(e)
	{
		var currKey = 0, e = e || event;
		currKey = e.keyCode || e.which || e.charCode;// 支持IE、FF
		if (currKey == 13) 
		{
			$("#member_search").click();
		}
	}
	
});

function initPage()
{
	//分页，PageCount是总条目数，这是必选参数，其它参数都是可选  
	$("#member_pagination").pagination(total, {  
	    callback: PageCallback1,  
	    prev_text: '上一页',       //上一页按钮里text  
	    next_text: '下一页',       //下一页按钮里text
	    items_per_page: pageSize,  //显示条数  
	    num_display_entries: 6,    //连续分页主体部分分页条目数  
	    current_page: pageIndex,   //当前页索引  
	    num_edge_entries: 2        //两侧首尾分页条目数  
	});  
	      
	//翻页调用  
	function PageCallback1(index, jq) 
	{
		InitTable(index); 
	}
}
//请求数据  
function InitTable(pageIndex) 
{
	var biz_zhy_code = $("#biz_zhy_code").val();
	var server_station_code = $("#server_station_code").val();
	var grade = $("#grade").attr("value");
	var memberType = $("#memberType").attr("value");
	var keyWord = $("#keyWord").val();
	pageIndex = parseInt(pageIndex)+1;
    $.ajax({   
        type: "POST",  
        dataType: "html",  
        url: '../member/member_list_data',      //提交到一般处理程序请求数据  
        data: {
        	page:pageIndex,
        	pageSize:pageSize,
        	biz_zhy_code:biz_zhy_code,
        	server_station_code:$("#server_station_code").val(),
    		grade:grade,
			memberType:memberType,
			keyWord:keyWord,
			searchState:"1"
        }, //提交两个参数：page(页面索引)，pageSize(显示条数)                  
        async: true,
        success: function(data) 
        { 
        	if(data==null)
        	{
        		return;
        	}
        	$("#member_show").empty().html(data);             //将返回的数据追加到表格  
        	var total1 = $("#total").val();
        	if(total != total1)
        	{
        		total = total1;
        		initPage();
        	}
        	hidePop();
        }  
    });              
}

// 删除老人会员调用===返回页面
function del_member_jsp(t){
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../member/del_member_jsp",
		async: true,
		data:{
			member_id:$(t).attr("value"),
			name:$(t).attr("name")
		},
		success : function(data) {
			$("#del_dialog").empty().html(data);
			deleteM(t,'deletepop');
		}
	});
}

//删除亲友会员调用===返回页面
function del_friends_jsp(t){
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../friends/del_friends_jsp",
		async: true,
		data:{
			friends_family_id:$(t).attr("value"),
			name:$(t).attr("name"),
			last_update_no:$(t).attr("updateno"),
		},
		success : function(data) {
			$("#del_dialog").empty().html(data);
			deleteM(t,'deletepop');
		}
	});
}

//激活老人会员调用===返回页面
function active_member_jsp(t){
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../member/active_member_jsp",
		async: true,
		data:{
			member_id:$(t).attr("value"),
			name:$(t).attr("name")
		},
		success : function(data) {
			$("#active_dialog").empty().html(data);
			deleteM(t,'activepop');
		}
	});
}


//删除老人会员操作
function del_member(){
	$.ajax({
		type : "post",
		dataType: "json",
		url : "../member/del_member",
		async: true,
		data:{
			server_station_code:$("#server_station_code").val(), 
			member_id:$("#del_member_id").val()
		},
		success : function(data) {
			if(data.data){
				//zhyAlert("删除成功");
				hideEdit();
				window.location = "../member/get_member_list";
			}else{
				zhyAlert("删除失败");
				hideEdit();
			}
		}
	});
}

//删除亲友会员操作
function del_friends(){
	$.ajax({
		type : "post",
		dataType: "json",
		url : "../friends/del_friends",
		async: true,
		data:{
			friends_family_id:$("#del_friends_id").val(),
			server_station_code:$("#server_station_code").val(),
			last_update_no:$("#last_update_no").val()
		},
		success : function(data) {
			if(data.data){
				//zhyAlert("删除成功");
				hideEdit();
				window.location = "../member/get_member_list?memberType=2";
			}else{
				zhyAlert("删除失败");
				hideEdit();
			}
		}
	});
}
//激活老人会员操作
function active_member(){
	$.ajax({
		type : "post",
		dataType: "json",
		url : "../member/active_member",
		async: true,
		data:{
			member_id:$("#active_member_id").val()
		},
		success : function(data) {
			if(data.data){
				//zhyAlert("激活成功");
				hideEdit();
				window.location = "../member/get_member_list";
			}else{
				zhyAlert("激活失败");
				hideEdit();
			}
		}
	});
}
//弹出窗展示
function deleteM(t,className){
	var tr=$(t).parents("tr");
	var top = parent.document.body.scrollTop||parent.document.documentElement.scrollTop;
	var this_h = $("." + className).height();
    var win_h = ($('html',parent.document).height()-this_h-100)/2
	
	if(win_h<0){
		top=0;
	}else{
		top= top +win_h;
	}
	$("." + className).css("top", top).show().siblings(".zhy_popa").hide();
	$(".zhy_zhezhao_pop").height($("html").height()).show();
}
//隐藏修改弹框
function hideEdit() {
	$("#active_dialog").empty();
	$("#del_dialog").empty();
	$(".zhy_zhezhao_pop").hide();
	$(".zhy_popa").hide();
	
}